﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Text;
using web.bussines;
using web.data.entities;
using web.core.Models;
using web.core.ViewModels;

namespace web.core.Controllers
{
    public class pageStaticController : baseController
    {
        #region page detail
        //page   detail
        public ActionResult detail()
        {
            return View();
        }

        [ChildActionOnly]
        public ActionResult page_detail(int? id)
        {
            //var alias_cate_str = "";
            //if (!string.IsNullOrEmpty(alias))
            //{
            //    alias_cate_str = alias;
            //}
            //else
            //{
            //    alias_cate_str = "tin_tuc";
            //}
            //var numberImg = 5;
            //var numberArticleRelate = 10;
            // int? languageId = languageModels.GetLanguageIDbyUrl(Request.Url.PathAndQuery);
            ViewModels.PageStaticViewModels uview;
            var item = pageStaticModels.getByID(id ?? 0);
            if (item != null)
            {
                uview = new ViewModels.PageStaticViewModels()
                {
                    page_id = item.page_id,
                    page_name = item.page_name,
                    link = item.link,
                    image_path = item.image_path,
                    summary = item.summary,
                    page_content = item.page_content,
                    title = item.title
                };

                
                //uview.list_article_relate = articleModels.GetListProductRelated(id ?? 0, numberArticleRelate);
            }
            else
            {
                uview = new ViewModels.PageStaticViewModels();
            }

            return PartialView("../Shared/pagestatic/page_detail", uview);
        }

        /// <summary>
        /// Get metadata for article detail
        /// </summary>
        /// <param name="cateId"></param>
        /// <returns></returns>
        [ChildActionOnly]
        public ActionResult page_detail_metadata(int? id)
        {
            //int? languageId = languageModels.GetLanguageIDbyUrl(Request.Url.PathAndQuery);
            var item = pageStaticModels.getByID(id ?? 0);
            var metadata_view = new ViewModels.MetadataViewModels();
            if (item != null)
            {
                metadata_view.title = string.IsNullOrEmpty(item.page_name) == false ? item.page_name : item.title;
                metadata_view.keyword = string.IsNullOrEmpty(item.keyword) == false ? item.keyword : "";
                metadata_view.description = string.IsNullOrEmpty(item.description) == false ? item.description : "";
            }
            base_metadata(metadata_view);
            return PartialView("../Shared/commont/metadata");
        }
        #endregion

        #region menu list page static
        [ChildActionOnly]
        public ActionResult menu_list_page_static()
        {
            int? languageId = languageModels.GetLanguageIDbyUrl(Request.Url.PathAndQuery);
           // var obj = new pageStaticModels();
            var lstPage = pageStaticModels.page_static_list_by_status(true, true, (int)languageId);
            StringBuilder str = new StringBuilder();
            foreach (var item in lstPage) {
                str.Append(string.Format("<dt class=\"nm\">- <a href='/thong_tin_ubuy/{0}_{1}.ub'>{2}</a></dt>", item.link, item.page_id, item.page_name));
            }

            var menu_view = new ViewModels.PageStaticListViewModels()
            {
                list_pstatic = lstPage,
                menu_list_page_static = str.ToString()
            };
            return PartialView("../Shared/pagestatic/menu_list_page", menu_view);
        } 
        #endregion
    }
}
